/*
 * Copyright (c) 2010-2011 Mark Allen.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.gifts.service.entity;

import static com.restfb.util.DateUtils.toDateFromLongFormat;
import static com.restfb.util.DateUtils.toDateFromMonthYearFormat;
import static com.restfb.util.DateUtils.toDateFromShortFormat;
import static com.restfb.util.StringUtils.isBlank;
import static java.util.Collections.unmodifiableList;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.restfb.Facebook;
import com.restfb.types.NamedFacebookType;
import com.restfb.util.ReflectionUtils;

/**
 * Entity class for FaceBookUser
 * 
 * @author dmaung
 *
 */
public class FacebookUser extends NamedFacebookType {

	private SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd");
	
	@Facebook("name")
	private String name;
	@Facebook("uid")
	private String userId;


	@Facebook("birthday_date")
	private String birthdayDate;
	
	@Facebook("birthday")
	private String birthday;
	
	
	@Facebook("pic_small")
	private String picSmall;

	@Facebook("pic")
	private String pic;

	public static final String SELECT_CLAUSE = "uid,name,first_name,middle_name,last_name,birthday,pic_small,pic,birthday_date";

	public String getName() {
		return this.name;
	}

	public String getBirthdayDate() {
		return this.birthdayDate;
	}


	
	
	
	
	public String getBirthdayShort() {
		String[] birthdayDateArray = getBirthdayDate() != null ? getBirthdayDate().split("\\/") : null;
		if(birthdayDateArray != null) {
			if(birthdayDateArray.length >= 2) {
				return birthdayDateArray[0]   + "/" + birthdayDateArray[1];
			}
		}
		return null;
	}
	
	public Date getBirthdayDayAsDate() {
		try {
			Date birthdate = dateFormat.parse(getBirthdayShort());
			
			Calendar now = Calendar.getInstance();
			if(birthdate.getMonth() < now.getTime().getMonth()) {
				birthdate.setYear(now.getTime().getYear()+1);
			} else {
				birthdate.setYear(now.getTime().getYear());
			}
			return birthdate;
		} catch(Exception e) {
			return null;
		}
		
	}
	
	
	public String getBirthday() {
		return birthday;
	}
	
	

	
	public String getPicSmall() {
		return picSmall;
	}
	
	public String getPic() {
		return pic;
	}
	
	public String getUserId() {
		return userId;
	}
}